package com.costeaalex.blueserver.interfaces.manager;

import javax.swing.JPanel;

import com.costeaalex.blueserver.interfaces.MainFrame;

public class ScreenManager extends Thread
	{
	
	private boolean isRunning=false;
	private boolean toNextScreen=false;
	private MainFrame mFL;
	private JPanel nextScreen;
	private int sleepTime=1000;
	
	public ScreenManager(MainFrame mF)
		{
		isRunning=true;
		mFL=mF;
		}
	
	public synchronized void setNextScreen(JPanel nS, int sT)
		{
		sleepTime=sT;
		nextScreen=nS;
		System.out.println("next screen");
		}
	
	public synchronized void toNextScreen(boolean tNS)
		{
		toNextScreen = tNS;
		}

	@Override
	public void run()
		{
		while(isRunning)
			{
			if(toNextScreen==true)
				{
				System.out.println("attempt change");
				try
					{
					sleep(sleepTime);
					} 
				catch (InterruptedException e)
					{
					e.printStackTrace();
					}
				if(nextScreen!=null)
					{
					mFL.setMainPanel(nextScreen);
					toNextScreen=false;
					}
				}
			}
		}
	
	}
